package com.fan;

import sun.audio.AudioPlayer;
import sun.audio.AudioStream;

import javax.swing.*;
import java.awt.*;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Random;

import static com.fan.MyJFrame.wordsArrayList;


/**
 * @description: 英语单词游戏
 * @author: fan
 * @date: 2022/1/24 13:32
 * @version: 1.0
 */
public class EnglishWordsGameMain {

    /**
     * 宽
     */
    public static int SCREEN_WIDTH;

    /**
     * 高
     */
    public static int SCREEN_HEIGHT;


    /**
     * 初始化位置
     */
    public static int INIT_POSITION;

    /**
     * 满屏最多10个单间
     */
    public static final int TOTAL = 10;
    public static int index;

    static Random random = new Random();

    static {

//        try {
//            //InputStream inputStream = EnglishWordsGameMain.class.getClassLoader().getResourceAsStream("music/demo.mp3");
//            FileInputStream fileau = new FileInputStream(new File("C:\\Users\\Administrator\\Desktop\\aaa.aac"));
//            AudioStream as = new AudioStream(fileau);
//            AudioPlayer.player.start(as);
//            AudioPlayer.player.start(as);
//            AudioPlayer.player.start(as);
//        } catch (Exception e) {
//            e.printStackTrace();
//            System.out.println("DFGHJKL");
//        }


        // 得到屏幕大小
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        SCREEN_WIDTH = (int) screenSize.getWidth();
        SCREEN_HEIGHT = (int) screenSize.getHeight();
        INIT_POSITION = SCREEN_WIDTH + 100;
        index = random.nextInt(TOTAL);
    }


    public static void main(String[] args) {
        new EnglishWordsGameMain();
    }

    public EnglishWordsGameMain() {
        init();
    }

    /**
     * 初始化方法
     */
    private void init() {

        MyJFrame jFrame = new MyJFrame();
        MyJPanel jPanel = new MyJPanel(wordsArrayList.get(index));

        jFrame.setSize(SCREEN_WIDTH, SCREEN_HEIGHT);
        //置窗口是否可以关闭
        jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        jFrame.add(jPanel);
        jFrame.setLocationRelativeTo(null);
        //设置窗口是否可见*/
        jFrame.setVisible(true);
    }

}
